package com.shop.cereshop.agent.controller.rank;

import com.shop.cereshop.agent.page.user.CereAgentUserVO;
import com.shop.cereshop.commons.constant.CoReturnFormat;
import com.shop.cereshop.commons.domain.agent.CereAgentRole;
import com.shop.cereshop.commons.result.Result;
import com.shop.cereshop.agent.page.rank.RankVO;
import com.shop.cereshop.agent.param.rank.AgentRankDTO;
import com.shop.cereshop.agent.service.rank.AgentRankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @description:
 * @author lx
 * @date 2025/10/18 16:38
 * @version 1.0
 */
@RestController
@RequestMapping("/rank")
@Api(value = "AgentRankController", tags = "代理商排名")
@RequiredArgsConstructor
public class AgentRankController {

    private final AgentRankService agentRankService;

    /**
     * 获取排名榜接口
     */
    @RequestMapping("/getRank")
    @ApiOperation(value = "获取排名榜接口")
    public Result<RankVO> getRank(@ModelAttribute("param") @Valid AgentRankDTO param, HttpServletRequest request) {
        //获取用户信息
        CereAgentUserVO user = ( CereAgentUserVO) request.getAttribute("user");
        if (user == null) {
            return Result.failed(CoReturnFormat.USER_NOT_LOGIN);
        }
        param.setAgentUserId(user.getAgentUserId());
        return Result.success(agentRankService.getRank(param));
    }
}
